package com.suitsoft.ut.web;

import java.util.List;
import java.util.Set;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springside.modules.utils.web.struts2.Struts2Utils;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.suitsoft.ut.commons.Constants;
import com.suitsoft.ut.commons.SystemCategorys;
import com.suitsoft.ut.commons.UserHolder;
import com.suitsoft.ut.entity.base.College;
import com.suitsoft.ut.entity.base.Discipline;
import com.suitsoft.ut.entity.base.Teacher;
import com.suitsoft.ut.entity.system.SystemInfo;
import com.suitsoft.ut.entity.thesis.Thesis;
import com.suitsoft.ut.entity.thesis.ThesisFile;
import com.suitsoft.ut.service.base.CollegeManager;
import com.suitsoft.ut.service.base.TeacherManger;
import com.suitsoft.ut.service.commons.DisciplineManager;
import com.suitsoft.ut.service.thesis.ThesisManager;

/**
 * 查看题目信息统一父类
 *@author Suineg
 */
@SuppressWarnings("serial")
public abstract class InitListActionSupport extends ActionSupport implements Preparable {
	/** 日志输出对象 */
	protected final Logger logger = LoggerFactory.getLogger(getClass());
	
	public static final String RELOAD = "reload";
	

	/** 题 服务层对象 */
	public ThesisManager thesisManager;
	/** 系统参数 */
	public SystemCategorys systemCategorys;
	/** 专业 管理服务层对象 */
	public DisciplineManager disciplineManager;
	/** 学院管理 服务层对象 */
	public CollegeManager collegeManager;
	/** 教师管理 服务层对象 */
	public TeacherManger teacherManger;
	
	
	/** 专业(系统所有) */
	public List<Discipline> disciplines;
	/** 当前用户可用学院 */
	public List<College> effectiveColleges;
	/** 登陆教师 */
	public Teacher loginTeacher;
	/** 科题来源 */
	public Set<SystemInfo> ketiSource;
	/** 理工类 */
	public Set<SystemInfo> ligongTypes;
	/** 文管类 */
	public Set<SystemInfo> wenguanTypes;

	public Long id;
	/** 题实体 */
	public Thesis thesis ;
	/** 流程实体 */
	public ThesisFile thesisFile;
	/** 访问Action方法之前 判断ID合法性和获取Thesis和ThesisFile 1 - 只判断ID 2 - 获取实体*/
	public int isPanDuanId;
	

	/**
	 * 初始化参数列表
	 */
	public void initList(){
		disciplines = disciplineManager.findByCollege(UserHolder.getLoginUser().getCollegeCode());
		effectiveColleges = collegeManager.getByUser();
		loginTeacher = teacherManger.findTeacherByUser(UserHolder.getLoginUser().getId());
		ketiSource = systemCategorys.getSystemParams().get(Constants.SYSTEM_CATEGORY_PK_KETI_SOURCE).getSystemInfo();
		ligongTypes = systemCategorys.getSystemParams().get(Constants.SYSTEM_CATEGORY_PK_LI_GONG_TYPE).getSystemInfo();
		wenguanTypes = systemCategorys.getSystemParams().get(Constants.SYSTEM_CATEGORY_PK_WEN_GUAN_TYPE).getSystemInfo();
	}
	
	/**
	 * 查看
	 * @return
	 */
	@Override
	public String input(){
		if(id == null || id == 0l){
			addActionMessage("非法操作！");
			return CrudActionSupport.RELOAD;
		}
		initList();
		thesis = thesisManager.get(id);
		thesisFile = thesis.getThesisFile();
		return INPUT;
	}
	

	public ThesisManager getThesisManager() {
		return thesisManager;
	}

	@Autowired
	public void setThesisManager(ThesisManager thesisManager) {
		this.thesisManager = thesisManager;
	}


	public List<Discipline> getDisciplines() {
		return disciplines;
	}

	public void setDisciplines(List<Discipline> disciplines) {
		this.disciplines = disciplines;
	}

	public List<College> getEffectiveColleges() {
		return effectiveColleges;
	}

	public void setEffectiveColleges(List<College> effectiveColleges) {
		this.effectiveColleges = effectiveColleges;
	}

	public Teacher getLoginTeacher() {
		return loginTeacher;
	}

	public void setLoginTeacher(Teacher loginTeacher) {
		this.loginTeacher = loginTeacher;
	}

	public Set<SystemInfo> getKetiSource() {
		return ketiSource;
	}

	public void setKetiSource(Set<SystemInfo> ketiSource) {
		this.ketiSource = ketiSource;
	}

	public Set<SystemInfo> getLigongTypes() {
		return ligongTypes;
	}

	public void setLigongTypes(Set<SystemInfo> ligongTypes) {
		this.ligongTypes = ligongTypes;
	}

	public Set<SystemInfo> getWenguanTypes() {
		return wenguanTypes;
	}

	public void setWenguanTypes(Set<SystemInfo> wenguanTypes) {
		this.wenguanTypes = wenguanTypes;
	}
	@Autowired
	public void setSystemCategorys(SystemCategorys systemCategorys) {
		this.systemCategorys = systemCategorys;
	}
	@Autowired
	public void setDisciplineManager(DisciplineManager disciplineManager) {
		this.disciplineManager = disciplineManager;
	}
	@Autowired
	public void setCollegeManager(CollegeManager collegeManager) {
		this.collegeManager = collegeManager;
	}
	@Autowired
	public void setTeacherManger(TeacherManger teacherManger) {
		this.teacherManger = teacherManger;
	}
	/**
	 * 访问所有Action之前都访问一次这个方法
	 */
	public void prepare() throws Exception {
		if(isPanDuanId == 1){
			if((id == null || id == 0l)){
				Struts2Utils.getResponse().sendRedirect("/ut/lllegal");
			}
		}else if(isPanDuanId == 2){
			if((id == null || id == 0l)){
				Struts2Utils.getResponse().sendRedirect("/ut/lllegal");
			}
			thesis = thesisManager.get(id);
			thesisFile = thesis.getThesisFile();
		}
	}
	public abstract Long getId() ;

	public abstract void setId(Long id);

	public abstract Thesis getThesis();

	public abstract void setThesis(Thesis thesis);

	public abstract ThesisFile getThesisFile();

	public abstract void setThesisFile(ThesisFile thesisFile);

//	public abstract void setIsPanDuanId(int isPanDuanId);
}

